*********"Environmental Ethical Justification Effects on Policy Acceptance"***********************
*************************written by Lauren Yehle*************************************************

*****************************************************************************************************

********OPEN "raw.xlsx"******************************************************************************
*cleaning data***************************************************************************************

drop if finished==0
keep if q_recaptchascore > 0.5
drop if q_recaptchascore == 0.5
drop if q_recaptchascore == .

drop if check_1== .
keep if check_1==8
drop if check_1_8_text == "-7"
drop if check_1_8_text == "0"
drop if check_1_8_text == "More than 7"
drop if check_1_8_text == "more than 7"
drop if check_1_8_text== ""

*generate dv*****************************************************************************************
generate dv=.

replace dv = 1 if (dv_infr_con==1| dv_infr_ant==1 | dv_infr_bio==1 | dv_cons_con==1 | dv_cons_ant==1 | dv_cons_bio==1)
replace dv = 2 if (dv_infr_con==2| dv_infr_ant==2 | dv_infr_bio==2 | dv_cons_con==2 | dv_cons_ant==2 | dv_cons_bio==2)
replace dv = 3 if (dv_infr_con==3| dv_infr_ant==3 | dv_infr_bio==3 | dv_cons_con==3 | dv_cons_ant==3 | dv_cons_bio==3)
replace dv = 4 if (dv_infr_con==4| dv_infr_ant==4 | dv_infr_bio==4 | dv_cons_con==4 | dv_cons_ant==4 | dv_cons_bio==4)
replace dv = 5 if (dv_infr_con==5| dv_infr_ant==5 | dv_infr_bio==5 | dv_cons_con==5 | dv_cons_ant==5 | dv_cons_bio==5)
replace dv = 6 if (dv_infr_con==6| dv_infr_ant==6 | dv_infr_bio==6 | dv_cons_con==6 | dv_cons_ant==6 | dv_cons_bio==6)
replace dv = 7 if (dv_infr_con==7| dv_infr_ant==7 | dv_infr_bio==7 | dv_cons_con==7 | dv_cons_ant==7 | dv_cons_bio==7)
drop if dv==.

*create treatment dummies******************************************************************************
generate a_dummy=.
replace a_dummy = 1 if (treat==2)
replace a_dummy = 0 if (treat==1)

generate b_dummy=.
replace b_dummy = 1 if (treat==3)
replace b_dummy = 0 if (treat==1)

generate ab_dummy=.
replace ab_dummy = 1 if (treat==3)
replace ab_dummy = 0 if (treat==2)

*to create new demographic and background variables***************************************************
generate newparty = .
replace newparty = 0 if (pol==1 | pollean==1)
replace newparty = 1 if (pol==2 | pollean==2)

generate newsex=.
replace newsex=1 if (sex==2)
replace newsex=0 if (sex==1)

generate newedu=.
replace newedu=1 if (edu==1 | edu==2)
replace newedu=2 if (edu==3 | edu==4)
replace newedu=3 if (edu==5)
replace newedu=4 if (edu==6 | edu==7 | edu==8)

generate newin=.
replace newin=1 if (income==1 | income==2 | income==3)
replace newin=2 if (income==3 | income==4)
replace newin=3 if (income==5 | income==6)

generate newlo=.
replace newlo=1 if (rural==1 | rural==2)
replace newlo=2 if (rural==3 | rural==4)
replace newlo=3 if (rural==5 | rural==6)

*drop unanalyzed variables************************************************************************
drop infr_con_time_firstclick infr_con_time_lastclick infr_con_time_pagesubmit infr_con_time_clickcount infr_ant_time_firstclick infr_ant_time_lastclick infr_ant_time_pagesubmit infr_ant_time_clickcount infr_bio_time_firstclick infr_bio_time_lastclick infr_bio_time_pagesubmit infr_bio_time_clickcount cons_con_time_firstclick cons_con_time_lastclick cons_con_time_pagesubmit cons_con_time_clickcount cons_ant_time_firstclick cons_ant_time_lastclick cons_ant_time_pagesubmit cons_ant_time_clickcount cons_bio_time_firstclick cons_bio_time_lastclick cons_bio_time_pagesubmit cons_bio_time_clickcount

*****************************************************************************************************
*****************************************************************************************************

*****start here...OPEN "clean.xlsx"******************************************************************

***desciptor data for table 1***
tabstat dv, statistics (mean count sd semean) by (treat)
tabstat dv, statistics (mean count sd semean) by (group)

***descriptor data for table 2***
tabstat percievedjust, statistics (mean count sd semean) by (treat)
tabstat percievedjust, statistics (mean count sd semean) by (case)
tabstat preferredjust, statistics (mean count sd semean) by (treat)
tabstat preferredjust, statistics (mean count sd semean) by (case)
tabstat env_con_1, statistics (mean count sd semean) by (treat)
tabstat env_con_1, statistics (mean count sd semean) by (case)
tabstat env_inst_1, statistics (mean count sd semean) by (treat)
tabstat env_inst_1, statistics (mean count sd semean) by (case)
tabstat newparty, statistics (mean count sd semean) by (treat)
tabstat newparty, statistics (mean count sd semean) by (case)

***check randomization of groups and background variables***
anova group sex
anova group age
anova group edu
anova group newedu
anova group income
anova group newin
anova group rural
anova group newlo
anova group newparty
anova group env_con_1
anova group env_inst_1

***normality checks for outcome variables***
swilk	dv
sktest dv
swilk	percievedjust
sktest percievedjust
swilk preferredjust
sktest preferredjust

*hypothesis 1 tests**********************************************************************************
***hypothesis 1a and 1b testing***
ttest dv, by (a_dummy)
esize twosample dv, by (a_dummy)
sdtest dv, by (a_dummy)
reg dv i.a_dummy
estimates store M1

ttest dv, by (b_dummy)
esize twosample dv, by (b_dummy)
sdtest dv, by (b_dummy)
reg dv b_dummy
estimates store M2

***check the cases interaction h1***
reg dv a_dummy##i.case
estimates store M3
reg dv b_dummy##i.case
estimates store M4

*hypothesis 2 tests**********************************************************************************
***hypothesis 2 testing***
ttest dv, by (ab_dummy)
esize twosample dv, by (ab_dummy)
sdtest dv, by (ab_dummy)
reg dv ab_dummy
estimates store M5

***check the cases interaction h2***
reg dv ab_dummy##i.case
estimates store M6

esttab M1 M2 M3 M4 M5 M6 using "PRIMARY.rtf", ar2 r2 replace se

*******CREATE FIGURE 1*******
reg dv i.treat i.case
margins, at (case = (1 2) treat =(1 2 3)) atmeans vsquish
marginsplot

*comprehension check tests**********************************************************************************
***generating robust outcome variables***
gen rdv = dv if check_2_correct==1
gen rperc = percievedjust if check_2_correct==1
gen rpref = preferredjust if check_2_correct==1

***hypothesis 1 tests with comprehension check***
ttest rdv, by (a_dummy)
esize twosample dv, by (a_dummy)
sdtest rdv, by (a_dummy)
reg rdv i.a_dummy
estimates store RM1

ttest rdv, by (b_dummy)
esize twosample rdv, by (b_dummy)
sdtest rdv, by (b_dummy)
reg rdv b_dummy
estimates store RM2

reg rdv a_dummy##i.case
estimates store RM3
reg rdv b_dummy##i.case
estimates store RM4

***hypothesis 2 tests with comprehension check***
ttest rdv, by (ab_dummy)
esize twosample rdv, by (ab_dummy)
sdtest rdv, by (ab_dummy)
reg rdv ab_dummy
estimates store RM5

reg rdv ab_dummy##i.case
estimates store RM6

esttab RM1 RM2 RM3 RM4 RM5 RM6 using "ROBUST.rtf", ar2 r2 replace se

*spillover effects**********************************************************************************
***descriptors***
tabstat percievedjust, statistics (mean count sd semean) by (treat)
tabstat percievedjust, statistics (mean count sd semean) by (group)
tabstat preferredjust, statistics (mean count sd semean) by (treat)
tabstat preferredjust, statistics (mean count sd semean) by (group)
tabstat rperc, statistics (mean count sd semean) by (treat)
tabstat rperc, statistics (mean count sd semean) by (group)
tabstat rpref, statistics (mean count sd semean) by (treat)
tabstat rpref, statistics (mean count sd semean) by (group)

***effect of treatment***
reg percievedjust i.treat
estimates store S1

reg rperc i.treat
estimates store S2

reg preferredjust i.treat
estimates store S3

reg rpref i.treat
estimates store S4

esttab S1 S2 S3 S4 using "SPILLOVER.rtf", ar2 r2 replace se

***interaction with case***
reg percievedjust a_dummy##i.case
estimates store S5

reg percievedjust b_dummy##i.case
estimates store S6

reg preferredjust a_dummy##i.case
estimates store S7

reg preferredjust b_dummy##i.case
estimates store S8

esttab S5 S6 S7 S8 using "SPILLOVERINTERACTION.rtf", ar2 r2 replace se

*******CREATE FIGURE 2*******
reg percievedjust i.treat i.case
margins, at (treat= (1 2 3)) saving (graph1, replace)
reg preferredjust i.treat i.case
margins, at (treat= (1 2 3)) saving (graph2, replace)
combomarginsplot graph1 graph2, labels ("Perceived Justification" "Preferred Justification") title ("Perceived and Preferred Justification Predicted Values") subtitle ("In general, what do you think the government is/should be most concerned for...?")

*additional analysis**********************************************************************************
***political identification, environmental concern, intrinsic evaluation of nature***
reg dv i.newparty
estimates store E1

reg dv i.treat i.case i.newparty i.case##i.newparty
estimates store E2

reg dv c.env_con_1
estimates store E3

reg dv i.case i.treat c.env_con_1 i.case##c.env_con_1
estimates store E4

reg dv c.env_inst_1
estimates store E5

reg dv i.case i.treat c.env_inst_1 i.case##c.env_inst_1
estimates store E6

esttab E1 E2 E3 E4 E5 E6 using "ADDITIONAL.rtf", ar2 r2 replace se

*******CREATE FIGURE 3*******
reg dv i.treat i.case i.newparty i.case##i.newparty
margins, at (case=(1,2) newparty=(0,1))
marginsplot

***interaction of evaluation and treatment***
reg dv i.case i.treat i.env_inst_1 i.treat##i.env_inst_1
estimates store E7
esttab E7 using "ADDITIONAL2.rtf", ar2 r2 replace se

*******CREATE FIGURE in supplementary materials*******
reg dv i.case i.treat i.env_inst_1 i.treat##i.env_inst_1
margins, at (env_inst_1 =(1,2,3,4,5,6,7) treat= (1 2 3))
marginsplot

*demographic analysis**********************************************************************************
***descriptor***
tabstat age, statistics (mean count sd semean) by (treat)
tabstat age, statistics (mean count sd semean) by (case)
tabstat newsex, statistics (mean count sd semean) by (treat)
tabstat newsex, statistics (mean count sd semean) by (case)
tabstat newedu, statistics (mean count sd semean) by (treat)
tabstat newedu, statistics (mean count sd semean) by (case)
tabstat newlo, statistics (mean count sd semean) by (treat)
tabstat newlo, statistics (mean count sd semean) by (case)
tabstat newin, statistics (mean count sd semean) by (treat)
tabstat newin, statistics (mean count sd semean) by (case)

reg dv i.case i.treat i.newedu i.newin i.newsex i.newlo
estimates store D1
reg dv i.case i.treat i.newedu i.newin i.newsex i.newlo env_con_1
estimates store D2

esttab D1 D2 using "DEMOGRAPHICS.rtf", ar2 r2 replace se

